package com.smm.web.vmc.domain;

/**
 * Created by zhenghao on 2016/9/29.
 *
 * 分页对象，保存分页数据
 */
public class Pager {

    private int pageNo;         //当前页码

    private int pageCount;        //总页数

    private int pageSize=10;  //每页记录数 , 默认 10条

    private int rowCount;         //总记录数


    public Pager(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {

        this.rowCount = rowCount;

        if(rowCount==0){

            this.pageCount =1;

            return;
        }


        //计算总页数
        if(pageSize==0) {

            this.pageCount=0;

        }else{

            this.pageCount = (int) Math.ceil((double)rowCount /(double) pageSize);
        }

    }

    public int firstResultIndex() {

        System.out.println("pageNo:"+pageNo);
        System.out.println("pageCount:"+pageCount);

        if(pageNo==0) pageNo=1;

        if(pageNo>pageCount) pageNo = pageCount;

        return (pageNo-1)* pageSize;
    }


    @Override
    public String toString() {
        return "Pager{" +
                "pageNo=" + pageNo +
                ", pageCount=" + pageCount +
                ", pageSize=" + pageSize +
                ", rowCount=" + rowCount +
                '}';
    }


    public static void main(String[] args) {

        System.out.println( (int)Math.ceil((double)18/(double)10));

    }

}
